package hlhj.fhp.checkpoint.atys

import android.content.Intent
import android.graphics.Color
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import com.huantansheng.easyphotos.models.puzzle.Line
import com.liaoinstan.springview.container.DefaultFooter
import com.liaoinstan.springview.container.DefaultHeader
import com.liaoinstan.springview.widget.SpringView
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.ReportAdp
import hlhj.fhp.checkpoint.iview.ReportCenterView
import hlhj.fhp.checkpoint.javaBean.ReportCenterBean
import hlhj.fhp.checkpoint.presenter.ReportCenterPresenter
import kotlinx.android.synthetic.main.aty_report_center.*
import kotlinx.android.synthetic.main.lo_pub_head.*
import kotlinx.android.synthetic.main.lo_publist.*

/**
 * Created by Never Fear   on 2018\11\22 0022.
Never More....
 */
class ReportCenterAty :BaseAty<ReportCenterView,ReportCenterPresenter>(), ReportCenterView, SpringView.OnFreshListener {
    private var reportListAdp:ReportAdp?=null
    private var datas=ArrayList<ReportCenterBean.InfoBean.ListBean.DataBean>()
    private var page=1
    private var emptyView: View?=null
    companion object {
         var type=1
    }
    override fun initView() {
        tvTittle.text="反馈中心"
        btRightIcon.visibility=View.VISIBLE
        btRightIcon.setImageResource(R.drawable.ic_tj)
        reportListAdp= ReportAdp(datas)

        listView.adapter=reportListAdp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)

        emptyView=LayoutInflater.from(this).inflate(R.layout.empty_view,null)
        reportListAdp?.setEmptyView(R.layout.empty_view,listView)

        spView.footer=DefaultFooter(this)
        spView.header=DefaultHeader(this)
    }

    override fun setReportList(reportCenterBean: ReportCenterBean) {
        spView?.onFinishFreshAndLoad()
        if(page==1){
            datas.clear()
        }
        datas.addAll(reportCenterBean.info.list.data)
        reportListAdp?.notifyDataSetChanged()
    }

    override fun logicStart() {
        presenter?.getList(type,page,this)
    }
    override fun setListener() {
        btRightIcon.setOnClickListener {
            val intent = Intent(this, ReportAty::class.java)
            startActivityForResult(intent,1)
        }
        spView.setListener(this)

        btAll.setOnClickListener {
            btAll.setTextColor(Color.parseColor("#FF1290F2"))
            btYes.setTextColor(Color.parseColor("#FF585F65"))
            page=1
            type=1
            presenter?.getList(type,page,this)

        }
        btYes.setOnClickListener {
            btYes.setTextColor(Color.parseColor("#FF1290F2"))
            btAll.setTextColor(Color.parseColor("#FF585F65"))
            page=1
            type=0
            presenter?.getList(type,page,this)
        }
    }

    override fun onLoadmore() {
        page++
        presenter?.getList(type,page,this)

    }

    override fun onRefresh() {
        page=1
        presenter?.getList(type,page,this)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode!=-1)return
        when(requestCode){
            1->{
                page=1
                presenter?.getList(type,page,this)
            }
        }
    }
    override fun bindView(): ReportCenterView {
        return this
    }
    override fun createPresenter(): ReportCenterPresenter {
        return ReportCenterPresenter()
    }

    override val contentId: Int= R.layout.aty_report_center
}